package io.renren.modules.emp.controller;

import java.util.Arrays;
import java.util.Map;

import io.renren.modules.emp.entity.LocationsEntity;
import io.renren.modules.emp.service.LocationsService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2022-04-07 18:14:57
 */
@RestController
@RequestMapping("/locations")
public class LocationsController {
    @Autowired
    private LocationsService locationsService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = locationsService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{cityId}")
    @RequiresPermissions("generator:locations:info")
    public R info(@PathVariable("cityId") Integer cityId){
		LocationsEntity locations = locationsService.getById(cityId);

        return R.ok().put("locations", locations);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("generator:locations:save")
    public R save(@RequestBody LocationsEntity locations){
		locationsService.save(locations);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("generator:locations:update")
    public R update(@RequestBody LocationsEntity locations){
		locationsService.updateById(locations);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("generator:locations:delete")
    public R delete(@RequestBody Integer[] cityIds){
		locationsService.removeByIds(Arrays.asList(cityIds));

        return R.ok();
    }

}
